
var resources = ['static/js/riot.min.js', 'static/js/sortable.min.js', 'static/js/jscolor.min.js', 'static/js/redux.min.js'];

if(pip.ie() && pip.ie() < 9){
  alert('请升级您的浏览器.');
}

if('Promise' in window === false){
  resources.push('static/js/promise.min.js');
}

pip.load(resources).on('done', function(){

  var app = new RiotApp({
    id: 'comail',
    version: '1.0',
    json: 'static/comail.json',
    preload: function(){
      return pip.load(app.data.tags.common);
    },
    debug: true
  });

  app.on('init::data', function(){

    var
      prefix = '//' + (app.data.env !== 'pro' ? app.data.env + '.' : ''),
      pw = {
        dev: {
          uid: 1,
          appkey: 'mwsite',
          'access-token': 'aff001f8e787de2852b6e05395cd4c60',
          'expire-timestamp': 1486623516045
        }
      };


    app.api = function(method, url, data, opts){
      var opts = opts || {};
      if(opts.trigger) opts.trigger.disabled = true;
      app.emit('api::start');
      return pip.xhr(prefix+'sosho.cn:8365/server/api/'+url, {
        method: method,
        data: data || {},
        headers: pip.assign(pw[app.data.env], opts.headers || {})
      }).on('done', function(resp){
        if(resp.errno != 0){
          app.log('api error:', resp.errmsg);
          app.emit('api::error', resp.errmsg);
        }
      }).on('complete', function(){
        if(opts.trigger) opts.trigger.disabled = false;
        app.emit('api::complete');
      });
    }

  });

});
